<template>
  <view class="view">
    <view>tempFilePath:</view>
    <input v-model="tempFilePath" placeholder="tempFilePath" type="text" />
    <view>fileList:</view>
    <text v-for="(item,index) in fileList" :key="index" selectable>{{item.filePath}}</text>
    <view>savedFilePath:</view>
    <input v-model="savedFilePath" placeholder="savedFilePath" type="text" />

    <button @click="chooseVideo">chooseVideo</button>
    <button @click="chooseImage">chooseImage</button>
    <button @click="getImageInfo">getImageInfo</button>

    <button @click="getFileInfo">getFileInfo</button>
    <button @click="saveFile">saveFile</button>
    <button @click="getSavedFileList">getSavedFileList</button>
    <button @click="getSavedFileInfo">getSavedFileInfo</button>
    <button @click="removeSavedFile">removeSavedFile</button>
  </view>
</template>

<script>
export default {
  data () {
    return {
      tempFilePath: '',
      savedFilePath: '',
      fileList: []
    }
  },
  methods: {
    chooseVideo () {
      uni.chooseVideo({
        success: (res) => {
          console.log(res)
          this.tempFilePath = res.tempFilePath
        },
        fail (err) {
          console.log(err)
        }
      })
    },
    chooseImage () {
      uni.chooseImage({
        success: (res) => {
          console.log(res)
          this.tempFilePath = res.tempFilePaths[0]
        },
        fail (err) {
          console.log(err)
        }
      })
    },
    getImageInfo () {
      uni.getImageInfo({
        src: this.tempFilePath,
        success: (res) => {
          console.log(res)
        },
        fail (err) {
          console.log(err)
        }
      })
    },
    getFileInfo () {
      uni.getFileInfo({
        filePath: this.tempFilePath,
        success: (res) => {
          console.log(res)
        },
        fail (err) {
          console.log(err)
        }
      })
    },
    saveFile () {
      uni.saveFile({
        tempFilePath: this.tempFilePath,
        success: (res) => {
          console.log(res)
          this.savedFilePath = res.savedFilePath
        },
        fail (err) {
          console.log(err)
        }
      })
    },
    getSavedFileList () {
      uni.getSavedFileList({
        success: (res) => {
          console.log(res)
          this.fileList = res.fileList
        },
        fail (err) {
          console.log(err)
        }
      })
    },
    getSavedFileInfo () {
      uni.getSavedFileInfo({
        filePath: this.savedFilePath,
        success: (res) => {
          console.log(res)
        },
        fail (err) {
          console.log(err)
        }
      })
    },
    removeSavedFile () {
      uni.removeSavedFile({
        filePath: this.savedFilePath,
        success: (res) => {
          console.log(res)
        },
        fail (err) {
          console.log(err)
        }
      })
    }
  }
}
</script>

<style>
text {
  word-break: break-all;
}
</style>